<?php


namespace app\admin\controller\orev;

use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;
use think\facade\Db;

/**
 * @ControllerAnnotation(title="订单评价列表")
 */
class OrderEvaluate extends AdminController
{

    use \app\admin\traits\Curd;
    protected $sort = [
        'id'   => 'desc',
    ];

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new \app\admin\model\OrderEvaluate();
        
    }
    
    /**
     * @NodeAnotation(title="列表")
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            list($page, $limit, $where) = $this->buildTableParames();
            $count = $this->model
                ->where($where)
                ->count();
            $list = $this->model
                ->where($where)
                ->page($page, $limit)
                ->order($this->sort)
                ->select();
            foreach ($list as $k => $v){
                $service_technician = Db::name("service_technician")->where("id",$v["service_technician_id"])->find();
                $order = Db::name("order")->where("id",$v["oid"])->find();
                $service_goods = Db::name("service_goods")->where("id",$order["service_goodid"])->find();
                $user = Db::name("user")->where("id",$v["uid"])->find();
                $v['user_name'] = $user['nickname'];
                $v['order_no'] = $order['order_no'];
                $v['service_goodsname'] = $service_goods['title'];
                $v['service_name'] = $service_technician['service_name'];
                $list[$k] = $v;
            }
            $data = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }

    //技师列表
    public function qwe(){
        $coupon = Db::name('service_technician')->order('id desc')->field('id,service_name as name,phone as text')->select()->toArray();
        return json($coupon);
    }

    /**
    * @NodeAnotation(title="编辑")
    */
    public function edit()
    {
        if ($this->request->isAjax()) {
            $post = $this->request->param();
            dump($post);die;
            if(empty($post['xuanzhong'])){
                $this->error('技师未选中');
            }
            $xuanzhong = explode(',',$post['xuanzhong']);
            $xuanzhong = array_filter($xuanzhong);
            foreach($xuanzhong as $k=>$v){
                $data = [
                    'service_user_id'=>$v,
                    'oid'=>$post['xid']
                ];
                Db::name('order_scanning_code')->insert($data);
            }
            $result = [
                'code'=>1,
                'msg' =>'分配成功'
            ];
            return $result;
        }else{
            $post = $this->request->param(); 
            $row = $this->model->where('id',$post['id'])->find();
            $this->assign('row',$row);
        }
        return $this->fetch();
    }

    
 
} 